<?php
// 设置脚本类型
header('content-type:application/json;charset=UTF-8');

$connect = mysqli_connect('127.0.0.1', 'root', 'root', 'student');
$sql = "select sex, count(*) as total 
FROM emp
where sex in ('男', '女')
group by sex";
$query = mysqli_query($connect, $sql);
$data = mysqli_fetch_all($query);
// print_r($data);d

$sex = [];
$sum = [];
foreach ($data as $value) {
    $sex[] = $value['0'];
    $sum[] = $value['1'];
}
echo json_encode(['code' => 1, 'msg' => '查询成功', 'data' => [
    'sex' => $sex,
    'sum' => $sum
]
]);